package treeset;

import java.util.TreeSet;
/**
 * TreeSet中存入自定义引用类型,按照指定规则排序
 * 按照人的年龄从小到大排序
 */
public class TreeSetDemo04 {
    public static void main(String[] args) {
        //method();
        TreeSet<Person> ts = new TreeSet<>();
        Person p1 = new Person("xiaoxin", 18);
        Person p2 = new Person("xiaotianin", 18);//年龄相同
        Person p3 = new Person("xiaowang", 20);

        ts.add(p1);
        ts.add(p2);
        ts.add(p3);

        System.out.println(ts);
    }

    private static void method() {
        TreeSet<Person> ts = new TreeSet<>();
        Person p1 = new Person("xiaoxin", 18);
        Person p2 = new Person("xiaotianin", 19);
        Person p3 = new Person("xiaowang", 20);

        ts.add(p1);
        ts.add(p2);
        ts.add(p3);

        System.out.println(ts);
    }
}
